home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE11 / GETRING / PHONE.C < prev    next >
C/C++ Source or Header  |  1996-04-28  |  22KB  |  653 lines

  1. #include <windows.h> 
  2. #include <windowsx.h> 
  3. #include "phone.h" 
  4. #include "tapi.h"
  5.  
  6. #define BUFSIZE 256
  7. #define APIHIVERSION     0x00010028    /* 1.40 */
  8. #define APILOWVERSION    0x00010000    /* 1.0 */
  9. #define EXTHIVERSION     0x00010005    /* 1.5 */
  10. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  11. #define MAX_PHONE        2
  12. #define OWNER            0
  13. #define MONITOR        1
  14.  
  15. LPCTSTR lpszAppName = "phoneGetRing";
  16. LPCTSTR lpszTitle   = "phoneGetRing"; 
  17.  
  18.  
  19. #if defined (WIN32)
  20.     #define IS_WIN32 TRUE
  21. #else
  22.     #define IS_WIN32 FALSE
  23. #endif
  24.  
  25. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  26. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  27. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  28.  
  29. HINSTANCE hInst;   // current instance
  30. HWND hWnd;         // parent window handle
  31. HWND hListWnd;     // listbox
  32. HDC  hdc;
  33. TEXTMETRIC  tm ;
  34.  
  35. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  36.  
  37.  
  38. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  39.                       LPTSTR lpCmdLine, int nCmdShow)
  40. {
  41.    MSG      msg;
  42.    WNDCLASS wc;
  43.  
  44.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  45.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  46.    wc.cbClsExtra    = 0;                      
  47.    wc.cbWndExtra    = 0;                      
  48.    wc.hInstance     = hInstance;              
  49.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  50.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  51.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  52.    wc.lpszMenuName  = lpszAppName;              
  53.    wc.lpszClassName = lpszAppName;              
  54.  
  55.    if ( IS_WIN95 )
  56.    {
  57.       if ( !RegisterWin95( &wc ) )
  58.          return( FALSE );
  59.    }
  60.    else if ( !RegisterClass( &wc ) )
  61.       return( FALSE );
  62.  
  63.    hInst = hInstance; 
  64.  
  65.    hWnd = CreateWindow( lpszAppName, 
  66.                         lpszTitle,    
  67.                         WS_OVERLAPPEDWINDOW, 
  68.                         CW_USEDEFAULT, 0, 
  69.                         CW_USEDEFAULT, 0,  
  70.                         NULL,              
  71.                         NULL,              
  72.                         hInstance,         
  73.                         NULL               
  74.                       );
  75.  
  76.    if ( !hWnd ) 
  77.       return( FALSE );
  78.  
  79.    ShowWindow( hWnd, nCmdShow ); 
  80.    UpdateWindow( hWnd );         
  81.  
  82.    while( GetMessage( &msg, NULL, 0, 0) )   
  83.    {
  84.       TranslateMessage( &msg ); 
  85.       DispatchMessage( &msg );  
  86.    }
  87.  
  88.    return( msg.wParam ); 
  89. }
  90.  
  91.  
  92. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  93. {
  94.     WNDCLASSEX wcex;
  95.  
  96.    wcex.style         = lpwc->style;
  97.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  98.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  99.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  100.    wcex.hInstance     = lpwc->hInstance;
  101.    wcex.hIcon         = lpwc->hIcon;
  102.    wcex.hCursor       = lpwc->hCursor;
  103.    wcex.hbrBackground = lpwc->hbrBackground;
  104.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  105.    wcex.lpszClassName = lpwc->lpszClassName;
  106.  
  107.    // Added elements for Windows 95.
  108.    //...............................
  109.    wcex.cbSize = sizeof(WNDCLASSEX);
  110.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  111.                             IMAGE_ICON, 16, 16,
  112.                             LR_DEFAULTCOLOR );
  113.             
  114.    return RegisterClassEx( &wcex );
  115. }
  116.  
  117. typedef struct tagMYINFO    // general application information
  118. {
  119.    HPHONEAPP phoneApp;      // instance handle TAPI gives back to us                                                                              through phoneInitialize()
  120.    DWORD dwNumDevices;     // number of available devices
  121.    DWORD dwAPIVersion;     // API version the phone supports
  122.     DWORD dwExtVersion;        // extended version
  123. } MYINFO;
  124.  
  125. typedef struct tagPHONEINFO  // information on an open phone
  126. {
  127.    HPHONE     hPhone;           // handle to the phone as returned by phoneOpen 
  128.     DWORD      dwDeviceID;            // device ID of the phone device
  129.     DWORD        dwRequestID;
  130.     char       szPhoneName[128]; // the phone's name 
  131. }PHONEINFO;
  132.  
  133. MYINFO myInfo;          //instance of MYINFO structure
  134. PHONEINFO myPhoneInfo[MAX_PHONE];  //instance of myPhoneInfo structure
  135.  
  136. LONG lRet;        //return code
  137. char buf[BUFSIZE];    // buffer for debug message
  138. char DataBuf[BUFSIZE]; //get/set data buffer;
  139.  
  140. DWORD i;
  141. DWORD dwHookSwitchDevs;
  142. DWORD dwLampMode;
  143. DWORD dwRingMode;
  144. DWORD dwRingVolume;
  145. DWORD dwHookSwitchVolume;
  146. DWORD dwPhoneStates;
  147. DWORD dwButtonModes;
  148. DWORD dwButtonStates;
  149. DWORD dwGain;
  150. HICON hIcon;
  151.  
  152. LONG lRet;
  153. char buf[BUFSIZE];
  154.  
  155. PHONECAPS*             pPhoneCaps;
  156. PHONEBUTTONINFO*  pButtonInfo;
  157. VARSTRING*            pVarString;
  158. PHONESTATUS*        pPhoneStatus;
  159. PHONEEXTENSIONID    ext_id;                                             
  160.  
  161.  
  162. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  163. {
  164.    switch( uMsg )
  165.    {
  166.       case WM_COMMAND :
  167.          switch( LOWORD( wParam ) )
  168.          {
  169.             case IDM_RUN :
  170.                pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  171.                    pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  172.                    phoneGetDevCaps(myInfo.phoneApp, OWNER, myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  173.                
  174.                if (pPhoneCaps->dwNumRingModes > 0)
  175.                     {
  176.                     lRet = phoneSetRing(myPhoneInfo[OWNER].hPhone, pPhoneCaps->dwNumRingModes, 150);
  177.                         if (lRet > 0)
  178.                       {
  179.                        myPhoneInfo[OWNER].dwRequestID = lRet;
  180.                       wsprintf(buf, "phoneSetRing proceeding!");
  181.                          SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  182.                       }
  183.                          else 
  184.                       {
  185.                          wsprintf( buf,"phoneSetRing failed, err=x%lx", lRet);
  186.                          phoneError(lRet);
  187.                          SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  188.                      
  189.                       }
  190.                      }
  191.                      
  192.                      else
  193.                     {
  194.                         wsprintf( buf,"The phone does not have the capability to set the ring modes.");
  195.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  196.                       phoneError(lRet);
  197.                }         
  198.  
  199.                lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  200.                    if (lRet == 0)
  201.                   {
  202.                    wsprintf(buf, "phoneGetRing succeeded!");
  203.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  204.                   if (dwRingMode == 0)
  205.                        {
  206.                            wsprintf(buf, "The phone device is currently not ringing.");
  207.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  208.                   }
  209.                        else
  210.                        {
  211.                            wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  212.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  213.                       wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  214.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  215.                        }
  216.                   }
  217.                     else 
  218.                   {
  219.                        wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  220.                       phoneError(lRet);
  221.                   }        
  222.                        
  223.                    free (pPhoneCaps);
  224.                    break;
  225.  
  226.             case IDM_EXIT :
  227.                for (i = 0; i < myInfo.dwNumDevices; i++)
  228.                     phoneClose(myPhoneInfo[i].hPhone);
  229.                 
  230.                    phoneShutdown(myInfo.phoneApp);
  231.                DestroyWindow( hWnd );
  232.                break;
  233.          
  234.             case IDM_ABOUT :
  235.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  236.                break;
  237.          }
  238.                 
  239.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  240.  
  241.       
  242.        case WM_CREATE :
  243.  
  244.           hdc = GetDC (hWnd) ;
  245.           GetTextMetrics (hdc, &tm) ;
  246.           ReleaseDC (hWnd, hdc) ;
  247.  
  248.           hListWnd = CreateWindowEx( 0, "listbox", 
  249.                         " ",    
  250.                         WS_CHILD | WS_VISIBLE,  
  251.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  252.                         tm.tmAveCharWidth * 16 +
  253.                                    GetSystemMetrics (SM_CXVSCROLL), 
  254.                         tm.tmHeight * 5,  
  255.                         hWnd,              
  256.                         NULL,              
  257.                         hInst,         
  258.                         NULL               
  259.                         );
  260.       
  261.              //phoneInitialize
  262.                //...............................................
  263.             lRet = phoneInitialize(&myInfo.phoneApp, hInst, phoneCallback, lpszAppName, &myInfo.dwNumDevices);
  264.             if (lRet == 0) 
  265.             {
  266.                 
  267.                wsprintf(buf, "phoneInitialize succeeded!");
  268.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  269.             }
  270.                
  271.                else 
  272.                {
  273.                    wsprintf( buf,"phoneInitialize failed, err=x%lx",lRet);
  274.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  275.                     phoneError(lRet);
  276.                     break;
  277.             }                    
  278.                
  279.             //phoneNegotiateAPIVersion
  280.                   //...............................................
  281.             lRet = phoneNegotiateAPIVersion(myInfo.phoneApp, 0, APILOWVERSION, APIHIVERSION, 
  282.                                                     &myInfo.dwAPIVersion, &ext_id);
  283.             if (lRet == 0)                        
  284.             {
  285.                wsprintf(buf, "phoneNegotiateAPIVersion succeeded!");
  286.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  287.             }
  288.                   else 
  289.                   {
  290.                    wsprintf(buf, "phoneNegotiateAPIVersion failed, err=x%lx", lRet);
  291.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  292.                     phoneError(lRet);
  293.                     phoneShutdown(myInfo.phoneApp);
  294.                break;
  295.              }
  296.  
  297.                //phoneNegotiateExtVersion
  298.                //...............................................
  299.             lRet = phoneNegotiateExtVersion(myInfo.phoneApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  300.                                                 EXTHIVERSION, &myInfo.dwExtVersion);
  301.             if (lRet == 0)                        
  302.             {
  303.                     wsprintf(buf, "phoneNegotiateExtVersion succeeded!");
  304.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  305.               }
  306.                   else 
  307.                {
  308.                     wsprintf(buf, "phoneNegotiateExtVersion failed, err=x%lx", lRet);
  309.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  310.                       phoneError(lRet);
  311.                }
  312.  
  313.             //phoneOpen
  314.                //................................................................
  315.                for (i = 0; i < myInfo.dwNumDevices; i++)
  316.                {
  317.                    if ( i == 0)
  318.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  319.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_OWNER);
  320.                    else
  321.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  322.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_MONITOR);
  323.                    
  324.                    if (lRet == 0)
  325.                    {
  326.                      wsprintf(buf, "phoneOpen succeeded!");
  327.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  328.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  329.                       pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  330.                          
  331.                       phoneGetDevCaps(myInfo.phoneApp,i,
  332.                       myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  333.                       strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  334.                   strcat( buf, " is the phone providor's name." );
  335.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  336.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  337.                      
  338.                   if (i == 0)
  339.                   {
  340.                      strcat( buf, " is the phone's name opened with OWNER privilege." );
  341.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  342.                   }
  343.                   else
  344.                   {
  345.                      strcat( buf, " is the phone's name opened with MONITOR privilege." );
  346.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  347.                   }
  348.                }
  349.                    else 
  350.                    {
  351.                        wsprintf( buf,"phoneOpen failed, err=x%lx", lRet);
  352.                        phoneError(lRet);
  353.                       break;
  354.                }
  355.                   } 
  356.  
  357.             break;
  358.       
  359.       case WM_SIZE:
  360.           MoveWindow(hListWnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  361.          break;
  362.  
  363.       case WM_DESTROY :
  364.          PostQuitMessage(0);
  365.          break;
  366.             
  367.       default :
  368.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  369.    }
  370.  
  371.    return( 0L );
  372. }
  373.  
  374.  
  375.  
  376. /****************************************************************************
  377.     FUNCTION: phoneCallback
  378.     PURPOSE:  callback function handles phone events
  379. ****************************************************************************/
  380. LRESULT CALLBACK phoneCallback (DWORD  dwDevice, DWORD dwMsg,
  381.                                 DWORD dwCallbackInst, DWORD dwParam1,
  382.                                 DWORD dwParam2,DWORD dwParam3)
  383. {
  384.     
  385.     switch (dwMsg)
  386.     {
  387.         case PHONE_REPLY:
  388.             if (dwParam1 == myPhoneInfo[OWNER].dwRequestID) 
  389.                    if (dwParam2 != 0)
  390.                 {
  391.                        wsprintf( buf,"Function failed, err=x%lx", lRet);
  392.                        phoneError(lRet);
  393.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  394.                    }
  395.             break;       
  396.  
  397.         case PHONE_STATE:
  398.         
  399.             if (dwParam1 == PHONESTATE_RINGMODE)
  400.             {
  401.                 lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  402.                 if (lRet == 0)
  403.                {
  404.                 wsprintf(buf, "phoneGetRing succeeded!");
  405.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  406.                if (dwRingMode == 0)
  407.                     {
  408.                         wsprintf(buf, "The phone device is currently not ringing.");
  409.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  410.                }
  411.                     else
  412.                     {
  413.                         wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  414.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  415.                    wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  416.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  417.                     }
  418.                }
  419.                  else 
  420.                {
  421.                     wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  422.                    phoneError(lRet);
  423.                }        
  424.               
  425.               break;
  426.               }
  427.             
  428.  
  429.             if (dwParam1 == PHONESTATE_SPEAKERHOOKSWITCH)
  430.             {   
  431.                 lRet = phoneGetHookSwitch(myPhoneInfo[OWNER].hPhone, &dwHookSwitchDevs);
  432.                 if (lRet == 0)
  433.                {
  434.                wsprintf(buf, "phoneGetHookSwitch succeeded!");
  435.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  436.                
  437.                if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER)
  438.                     {
  439.                         wsprintf(buf, "The phone's HookSwitch Speaker is offhook!");
  440.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  441.                     }
  442.                     else
  443.                     {
  444.                    wsprintf(buf, "The phone's HookSwitch Speaker is onhook!");
  445.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  446.                     }
  447.  
  448.               }
  449.                  else 
  450.                {
  451.                       wsprintf( buf,"phoneGetHookSwitch failed, err=x%lx", lRet);
  452.                    phoneError(lRet);
  453.                }    
  454.             break;                
  455.             }
  456.  
  457.             if (dwParam1 == PHONESTATE_SPEAKERVOLUME)
  458.             {   
  459.                 lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  460.                if (lRet == 0)
  461.                {
  462.                 wsprintf(buf, "phoneGetVolume succeeded!");
  463.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  464.                wsprintf(buf, "The current volume for the Speaker Hookswitch is x%lx", dwHookSwitchVolume);
  465.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  466.                }
  467.                  else 
  468.                {
  469.                     wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  470.                    phoneError(lRet);
  471.                }    
  472.             break;                
  473.             }
  474.  
  475.             if (dwParam1 == PHONESTATE_SPEAKERGAIN)
  476.             {   
  477.                 lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  478.                 if (lRet == 0)
  479.                {
  480.                   wsprintf(buf, "phoneGetGain succeeded!");
  481.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  482.                     wsprintf(buf, "The current Gain is x%lx", dwGain);
  483.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  484.                }
  485.                  else 
  486.                {
  487.                       wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  488.                     phoneError(lRet);
  489.                }
  490.             break;                
  491.             }
  492.             
  493.             if (dwParam1 == PHONESTATE_DISPLAY)
  494.             {   
  495.                 pVarString = (VARSTRING *) calloc (1, sizeof(VARSTRING)+1000);
  496.                 pVarString->dwTotalSize = sizeof(VARSTRING) + 1000;
  497.                 lRet = phoneGetDisplay(myPhoneInfo[OWNER].hPhone, pVarString);
  498.                 if (lRet == 0)
  499.                {
  500.                   wsprintf(buf, "phoneGetDisplay succeeded!");
  501.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  502.                strcpy(buf, lpszTitle);
  503.                //strcpy(buf, ((LPSTR)(pVarString)+pVarString->dwStringOffset));
  504.                strcat( buf, " is the current phone display." );
  505.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  506.                }
  507.                  else 
  508.                {
  509.                    wsprintf( buf,"phoneGetDisplay failed, err=x%lx", lRet);
  510.                   phoneError(lRet);
  511.                }    
  512.                     
  513.                 free (pVarString);
  514.                 break;
  515.               }
  516.    }
  517.    return (TRUE);
  518.  
  519.  
  520. /****************************************************************************
  521.     FUNCTION: phoneError
  522.     PURPOSE:  phone error messages
  523. ****************************************************************************/
  524. void phoneError (LONG lrc)
  525. {
  526.  switch (lrc) {
  527.     case PHONEERR_INVALAPPHANDLE:
  528.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  529.        break;
  530.     case PHONEERR_BADDEVICEID:
  531.        MessageBox (hWnd,"The specified phone device ID is out of range.", "", 
  532.                    MB_OK);
  533.        break;
  534.     case PHONEERR_INCOMPATIBLEAPIVERSION:
  535.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  536.        break;
  537.     
  538.     case PHONEERR_INVALBUTTONLAMPID:
  539.        MessageBox (hWnd, "Invalid Button Lamp ID.", "", MB_OK);
  540.        break;
  541.  
  542.     case PHONEERR_INVALBUTTONMODE:
  543.        MessageBox (hWnd, "Invalid Button Mode.", "", MB_OK);
  544.        break;
  545.  
  546.     case PHONEERR_INVALBUTTONSTATE:
  547.        MessageBox (hWnd, "Invalid Button State", "", MB_OK);
  548.        break;
  549.  
  550.     case PHONEERR_INUSE:
  551.        MessageBox (hWnd, "Phone in Use.", "", MB_OK);
  552.        break;
  553.     
  554.     case PHONEERR_INVALHOOKSWITCHDEV:
  555.        MessageBox (hWnd, "Invalid Hookswitch Device.", "", MB_OK);
  556.        break;
  557.  
  558.     case PHONEERR_INVALHOOKSWITCHMODE:
  559.        MessageBox (hWnd, "Invalid Hookswitch Device Mode.", "", MB_OK);
  560.        break;
  561.  
  562.     case PHONEERR_INVALLAMPMODE:
  563.        MessageBox (hWnd, "Invalid Lamp Mode.", "", MB_OK);
  564.        break;
  565.      
  566.     case PHONEERR_INCOMPATIBLEEXTVERSION:
  567.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  568.        break;
  569.     case PHONEERR_NOMEM:
  570.        MessageBox (hWnd, "No memory","", MB_OK);
  571.        break;
  572.     case PHONEERR_NODRIVER:
  573.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  574.        break;
  575.     case PHONEERR_RESOURCEUNAVAIL:
  576.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  577.        break;
  578.     case PHONEERR_ALLOCATED:
  579.        MessageBox (hWnd, "Allocation error", "", MB_OK);
  580.        break;
  581.     case PHONEERR_INVALDATAID:
  582.        MessageBox (hWnd, "The data ID is out of range.", "", MB_OK);
  583.        break;
  584.     case PHONEERR_INVALDEVICECLASS:
  585.        MessageBox (hWnd, "The device class was invalid.", "", MB_OK);
  586.        break;
  587.     case PHONEERR_INVALPOINTER:
  588.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  589.                    "", MB_OK);
  590.        break;
  591.     case PHONEERR_OPERATIONFAILED:
  592.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  593.        break;
  594.     case PHONEERR_INVALPHONEHANDLE:
  595.        MessageBox (hWnd, "Invalid phone handle", "", MB_OK);
  596.        break;
  597.     case PHONEERR_INVALPHONESTATE :
  598.        MessageBox (hWnd, "Invalid call state for this function.", "", MB_OK);
  599.        break;
  600.     case PHONEERR_INVALPRIVILEGE:
  601.        MessageBox (hWnd, "Invalid privilege for this function.", "", MB_OK);
  602.        break;
  603.     case PHONEERR_NODEVICE:
  604.        MessageBox (hWnd, "No associated device for given class",
  605.                    "", MB_OK);
  606.        break;
  607.     case PHONEERR_OPERATIONUNAVAIL:
  608.        MessageBox (hWnd, "The operation is unavailable",
  609.                    "", MB_OK);
  610.        break;
  611.     case PHONEERR_INVALPARAM:
  612.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  613.        break; 
  614.  
  615.     case PHONEERR_INVALRINGMODE:
  616.             MessageBox(hWnd, "Invalid Ring Mode", "", MB_OK);
  617.        break; 
  618.  
  619.     }
  620.     
  621.              
  622. }
  623.  
  624. LRESULT CALLBACK About( HWND hDlg,           
  625.                         UINT message,        
  626.                         WPARAM wParam,       
  627.                         LPARAM lParam)
  628. {
  629.    switch (message) 
  630.    {
  631.        case WM_INITDIALOG: 
  632.                return (TRUE);
  633.  
  634.        case WM_COMMAND:                              
  635.                if (   LOWORD(wParam) == IDOK         
  636.                    || LOWORD(wParam) == IDCANCEL)    
  637.                {
  638.                        EndDialog(hDlg, TRUE);        
  639.                        return (TRUE);
  640.                }
  641.                break;
  642.    }
  643.  
  644.    return (FALSE); 
  645. }
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.